package com.lianxian.xindong.home.di.module;

import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hxb.library.base.DefaultAdapter;
import com.hxb.library.di.scope.FragmentScope;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

import com.hxb.library.utils.AntiShakeUtils;
import com.lianxian.xindong.home.R;
import com.lianxian.xindong.home.mvp.contract.CircleContract;
import com.lianxian.xindong.home.mvp.model.CircleModel;
import com.lianxian.xindong.home.mvp.model.entity.CircleBean;
import com.lianxian.xindong.home.mvp.ui.activity.CircleDetailActivity;
import com.lianxian.xindong.home.mvp.ui.adapter.CircleAdapter;

import java.util.ArrayList;
import java.util.List;


/**
 * @作者：hexingbo
 * @时间：07/04/2023
 * @描述：
 */
@Module
public abstract class CircleModule {

    @Binds
    abstract CircleContract.Model bindCircleModel(CircleModel model);

    @FragmentScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManager(CircleContract.View view) {
        return new LinearLayoutManager(view.getContext());
    }

    @FragmentScope
    @Provides
    static List<CircleBean> provideList() {
        return new ArrayList<>();
    }

    @FragmentScope
    @Provides
    static RecyclerView.Adapter provideAdapter(CircleContract.View view, List<CircleBean> list) {
        CircleAdapter adapter = new CircleAdapter(list);
        adapter.setOnItemClickListener(new DefaultAdapter.OnRecyclerViewItemClickListener<CircleBean>() {
            @Override
            public void onItemClick(View v, int viewType, CircleBean data, int position) {
                if (AntiShakeUtils.isInvalidClick(v)) {
                    return;
                }
                if (v.getId()!= R.id.rcy_img&&v.getId()!=R.id.tv_zan){
                    view.launchActivity(new Intent(view.getContext(), CircleDetailActivity.class));
                }

            }
        });
        return adapter;
    }
}